package au.edu.swin.MelbourneMap;

import java.util.*;
import java.io.*;

/**
 * Data structure to define a graph. 
 *
 * @author  Alexis Wellavize (s/n: 6033482)<br/>
 * @since   v1, created:  24/10/2012
 * @version v1, modified:  24/10/2012
 *
 */
 
public final class Graph<Node>
{
    ArrayList<Node> neighbours;			// Indexed node adjacency list
    ArrayList<Double> distances;		// Indexed edge distances between nodes
    ArrayList<String> roads;		    // Indexed connected road names

    public Graph()
    {
        this.neighbours = new ArrayList<Node>();
        this.distances = new ArrayList<Double>();
        this.roads = new ArrayList<String>();
    }
    
    public ArrayList<Node> getNeighbours()
    {
        return neighbours;
    }
    
    public ArrayList<Double> getEdgeDistances()
    {
        return distances;
    }
    
    public ArrayList<String> getRoadNames()
    {
        return roads;
    }
    
    public Double getDistanceTo( Node node )
    {
        // If node defined as neighbour, get distance
        if ( neighbours.contains( node ) )
            return distances.get( neighbours.indexOf( node ) );
        else
            System.out.println( "ERR: Node not found in neighbour list!" );
            
        return 0.0;
    }
    
    public String getRoadTo( Node node )
    {
        // If node defined as neighbour, get road name
        if ( neighbours.contains( node ) )
            return roads.get( neighbours.indexOf( node ) );
        else
            System.out.println( "ERR: Node not found in neighbour list!" );
            
        return null;
    }

    public void addNeighbour( Node neighbour )
    {
        if ( !neighbours.contains( neighbour ) )
            neighbours.add( neighbour );	        // Add adjacent node to adjacency list
    }    
    
    public void addConnectedRoad( String road )
    {
        roads.add( road );
    }    

    public void addEdgeDistance( double distance )
    {
        distances.add( distance );
    }    
}
